package com.dc.around.Manage;

import com.dc.around.model.Information;
import com.dc.around.tools.Constant;
import com.dc.around.tools.Tools;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: Administrator
 * Date: 13-10-14
 * Time: 下午11:12
 * To change this template use File | Settings | File Templates.
 */
public class Manage {

       public List<Information>  getInformationList() throws JSONException, IOException {
           String Json    =   Tools.getJson(Constant.POI_GEO_URL+"?q=%E8%82%AF%E5%BE%B7%E5%9F%BA&coordinate=116.322479%2C39.980781&access_token="+Constant.SINA_ACCESS_TOKEN);
           JSONTokener jsonTokener = new JSONTokener(Json);

           List<Information> informationList = new ArrayList<Information>();
           JSONObject person = (JSONObject) jsonTokener.nextValue();

           JSONArray jsonArray = person.optJSONArray("poilist");

           for(int i = 0; i<jsonArray.length();i++){
               Information information = new Information();
               JSONObject jsonObject = new JSONObject(jsonArray.get(i).toString());
               information.setAddress(jsonObject.optString("address"));
               information.setDistance(jsonObject.optString("distance"));
               information.setImageid(jsonObject.optString("imageid"));
               information.setName(jsonObject.optString("name"));
               information.setTel(jsonObject.optString("tel"));
               information.setTimestamp(jsonObject.optString("timestamp"));
               information.setType(jsonObject.optString("type"));
               information.setX(jsonObject.optString("x"));
               information.setY(jsonObject.optString("y"));
               informationList.add(information);


           }




           return informationList;

       }
}
